import { constantRoutes, asyncRoutes } from '@/router'

const state = () => {
  return {
    routes: constantRoutes // 初始化静态路由
  }
}
const mutations = {
  setRoutes(state, otherRoutes) {
    // 在静态路由的基础上添加其它的路由
    state.routes = [...constantRoutes, ...otherRoutes]
  }
}
const actions = {
  // 筛选路由的权限
  filterRoutes(context, menus) {
    const otherRoutes = asyncRoutes.filter(item => {
      return menus.includes(item.children[0].name)
    })
    context.commit('setRoutes', otherRoutes)
    return otherRoutes // 把过滤后的路由返回,为了添加成为动态路由
  }
}
const getters = {

}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters

}
